package com.qcby.controller;

import com.qcby.common.LessonPlan.ShowByPage;
import com.qcby.dao.LessonPlanDao;
import com.qcby.entity.LessonPlan;
import com.qcby.entity.Result;
import com.qcby.service.LessonPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Controller
@Api(tags = "教案接口")
@RequestMapping("/LessonPlanManagement")
public class LessonPlanController {

    @Autowired
    private LessonPlanService lessonPlanService;

    @GetMapping("/ShowByPage")
    @ApiOperation(value = "分页展示教案信息")
    @ResponseBody
    public Result<List<LessonPlan>> showLessonPlanByPage(ShowByPage pageInfo){
        return lessonPlanService.showLessonPlanByPage(pageInfo);
    }

    @GetMapping("/GetLessonPlanCount")
    @ApiOperation(value = "获取满足条件的教案数量")
    @ResponseBody
    public Result<Integer> getLessonPlanCount(ShowByPage pageInfo) {
        return lessonPlanService.getLessonPlanCount(pageInfo);
    }

    @PostMapping("/AddLessonPlan")
    @ApiOperation(value = "添加教案信息")
    @ResponseBody
    public Result<LessonPlan> addLessonPlan(LessonPlan info) throws Exception {
        info.setCreatetime(LocalDateTime.now());
        System.out.println(info);
        return lessonPlanService.addLessonPlan(info);
    }

    @DeleteMapping("/DeleteLessonPlan")
    @ApiOperation(value = "删除教案信息")
    @ResponseBody
    public Result<Integer> deleteLessonPlan(int id){
        return lessonPlanService.deleteLessonPlan(id);
    }

    @GetMapping("/ShowLessonPlanDetail")
    @ApiOperation(value = "展示教案详细信息")
    @ResponseBody
    public Result<LessonPlan> showLessonPlanDetail(int id){
        return lessonPlanService.showLessonPlanDetail(id);
    }

    @PostMapping("/FuzzyQueryLessonPlanByPage")
    @ApiOperation(value = "模糊查询教案信息")
    @ResponseBody
    Result<List<LessonPlan>> fuzzyQueryLessonPlanByPage(ShowByPage info){
        return lessonPlanService.fuzzyQueryLessonPlanByPage(info);
    }

    @PostMapping("/GetLessonPlanCountWhenSearch")
    @ApiOperation(value = "在模糊查找的时候获取满足条件的教案数量")
    @ResponseBody
    public Result<Integer> getLessonPlanCountWhenSearch(ShowByPage pageInfo) {
        return lessonPlanService.getLessonPlanCountWhenSearch(pageInfo);
    }
    @PostMapping("/GetLessonPlanById")
    @ApiModelProperty(value = "通过id获取教案信息")
    @ResponseBody
    public Result getLessonPlanByTeacherName(Integer id) {
        return lessonPlanService.getLessonPlanByTeacherName(id);
    }

}
